package com.example.batchdemo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @author lzh
 * @date 2019/9/16 - 11:03
 *
 * 由于批处理作业和定时任务都需要使用到多线程，所以我们需要配置一下Spring的线程池
 */
@Configuration
public class ExecutorConfig {

    /**
     * 配置任务线程池执行器
     * @return  threadPoolTaskExecutor
     */
    @Bean
    public ThreadPoolTaskExecutor threadPoolTaskExecutor(){
        ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
        //核心线程池大小
        threadPoolTaskExecutor.setCorePoolSize(50);
        //线程池最大值
        threadPoolTaskExecutor.setMaxPoolSize(200);
        //队列容量
        threadPoolTaskExecutor.setQueueCapacity(1000);
        //线程名前缀
        threadPoolTaskExecutor.setThreadNamePrefix("Data-Job");
        return threadPoolTaskExecutor;
    }


}
